package com.apollographql.apollo.api.internal.json;

import com.apollographql.apollo.api.EnumValue;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.kt.Metadata;
import com.kt.jvm.JvmStatic;
import com.kt.jvm.internal.Intrinsics;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u001a\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\bÆ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u001a\u0010\u0003\u001a\u00020\u00042\b\u0010\u0005\u001a\u0004\u0018\u00010\u00012\u0006\u0010\u0006\u001a\u00020\u0007H\u0007¨\u0006\b"}, d2 = {"Lcom/apollographql/apollo/api/internal/json/Utils;", "", "()V", "writeToJson", "", "value", "jsonWriter", "Lcom/apollographql/apollo/api/internal/json/JsonWriter;", "apollo-api"}, k = 1, mv = {1, 4, 0})
/* compiled from: Utils.kt */
public final class Utils {
    public static final Utils INSTANCE = new Utils();

    private Utils() {
    }

    @JvmStatic
    public static final void writeToJson(Object value, JsonWriter jsonWriter) throws IOException {
        Intrinsics.checkParameterIsNotNull(jsonWriter, "jsonWriter");
        if (value == null) {
            jsonWriter.nullValue();
        } else if (value instanceof Map) {
            jsonWriter.beginObject();
            Object[] element=((Map) value).entrySet().toArray();
            for (int i=0;i<element.length;i++) {
                Map.Entry obj= (Map.Entry) element[i];
                Object key = obj.getKey();
                Object value2 = obj.getValue();
                jsonWriter.name(String.valueOf(key));
                writeToJson(value2, jsonWriter);
            }
            jsonWriter.endObject();
        } else if (value instanceof List) {
            jsonWriter.beginArray();
            for (Object element$iv2 : (Iterable) value) {
                writeToJson(element$iv2, jsonWriter);
            }
            jsonWriter.endArray();
        } else if (value instanceof Boolean) {
            jsonWriter.value((Boolean) value);
        } else if (value instanceof Number) {
            jsonWriter.value((Number) value);
        } else if (value instanceof EnumValue) {
            jsonWriter.value(((EnumValue) value).getRawValue());
        } else {
            jsonWriter.value(value.toString());
        }
    }
}
